﻿using Moq;
using NUnit.Framework;
using SUT.Validation;

namespace SUT.Fixture2.Validation
{
    [TestFixture]
    public class CompositeNodeFixture
    {
        private Mock<INode> m_mockFailingNode;
        private Mock<INode> m_mockGoodNode;

        [SetUp]
        public void Setup()
        {
            m_mockFailingNode = new Mock<INode>();
            m_mockGoodNode = new Mock<INode>();
            m_mockFailingNode.Setup(s => s.IsAlive()).Returns(false);
            m_mockGoodNode.Setup(s => s.IsAlive()).Returns(true);
        }

        [Test]
        public void IsAlive_AllNodeAreOk_True()
        {
            INode[] nodes = new[] { m_mockGoodNode.Object };
            CompositeNode node = new CompositeNode(nodes);
            Assert.IsTrue(node.IsAlive());
        }

        [Test]
        public void IsAlive_OneNodeisKo_False()
        {
            INode[] nodes = new[] { m_mockFailingNode.Object };
            CompositeNode node = new CompositeNode(nodes);
            Assert.IsFalse(node.IsAlive());
        }

        [Test]
        public void IsAlive_OneNodeisKoAndOneIsUp_False()
        {
            INode[] nodes = new[] { m_mockFailingNode.Object, m_mockGoodNode.Object };
            CompositeNode node = new CompositeNode(nodes);
            Assert.IsFalse(node.IsAlive());

            m_mockGoodNode.Verify(n => n.IsAlive(),Times.Never());
        }
    }
}
